﻿#include<iostream>
using namespace std;

//拷贝函数调用时机
//1.使用一个已经创建完毕的对象来初始化一个新对象
//2.值传递方式给函数参数传值
//3.值方式返回局部对象
class People
{
public:

	People()
	{
		cout << "new a person" << endl;
	}
	People(int a)
	{
		age = a;
		cout << "new a person" << age << endl;
	}
	People(const People& p)
	{
		cout << "拷贝" << endl;
		age = p.age;
	}
	~People()
	{
		cout << "delete a person and" << age << endl;
	}
	int age = 10;
};
void test171()
{
	People p1(20);
	People p2(p1);
	cout << "P2 age is" << p2.age << endl;
}
//2.值传递方式给函数参数传值
void doWork(People p)
{
	cout << p.age << endl;
}
void test172()
{
	People p;
	doWork(p);
}
//3.值方式返回局部对象
People doWork2()
{
	People p1;
	cout << (int*)&p1 << endl;
	return p1;
}
void test173()
{
	People p = doWork2();
	cout << (int*)&p<< endl;
}
int main17()
{
	test173();
	return 0;
}
